package cn.kw0501.tms.utils;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * KJ0301
 * @Description : 代码生成器
 * @Author : Aedes
 * @Date: 2022/8/8 9:55
 */
public class AutoCode {
    // 父级包的名字
    static String parStr = "cn.kw0501";
    // 模块名
    static String module = "tms";
    public static void main(String[] args) {
        //1.生成器创建
        AutoGenerator generator = new AutoGenerator();

        //2.完成全局设置
        GlobalConfig config = new GlobalConfig();
        config.setAuthor("Aedes")
                //生成类名称的设置
                .setMapperName("%sDao")
                .setServiceName("%sService")
                .setServiceImplName("%sServiceImpl")
                .setControllerName("%sController")
                //输出的设置
                .setOutputDir("e:\\mycode")
                .setFileOverride(true); //是否覆盖原来的文件
        generator.setGlobalConfig(config);

        //3.数据库连接配置
        DataSourceConfig sourceConfig = new DataSourceConfig();
        sourceConfig.setDbType(DbType.MYSQL)
                .setDriverName("com.mysql.cj.jdbc.Driver")
                .setUrl("jdbc:mysql://127.0.0.1:3306/qs_tms?serverTimezone=Asia/Shanghai")
                .setUsername("root")
                .setPassword("123456");
        generator.setDataSource(sourceConfig);

        //4.转换策略
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setNaming(NamingStrategy.underline_to_camel) //下划线转驼峰
                .setEntityLombokModel(true) //开启lombok
                .setChainModel(true)  //开启链式编程
                .setRestControllerStyle(true)
                .setTablePrefix("info_","order_","sto_","sys_"); //删除表前缀
        generator.setStrategy(strategyConfig);

        //5.包生成策略
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent(parStr)
                .setMapper(module+".dao")
                .setEntity(module+".entity")
                .setService(module+".service")
                .setServiceImpl(module+".service.impl")
                .setController(module+".controller");
        generator.setPackageInfo(packageConfig);

        //6.生成代码
        generator.execute();
    }

}


;